<template>
  <view class="goods-item" @click="goodsItemClickHandler">
    <view class="left">
      <!-- 图片区域 -->
      <view class="thumb-box">
        <radio :checked="goods.is_checked" color="#C00000" v-if="showRadio" @click="radioClickHandler" />
        <image :src="goods.goods_small_logo || defaultThumb" mode="" class="thumb"></image>
      </view>
    </view>
    <view class="right">
      <view class="title">{{goods.goods_name}}</view>
      <!-- 商品信息区域 -->
      <view class="desc-box">
        <view class="price">￥{{goods.goods_price}}</view>
        <uni-number-box :min="1" :value="goods.goods_count" :goodsid="goods.goods_id" v-if="showNoBox" @change="noboxChange"></uni-number-box>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    props: {
      goods: {
        type: Object,
        default: {}
      },
      showRadio: {
        type: Boolean,
        default: false
      },
      showNoBox: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        defaultThumb: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
      };
    },
    methods: {
      goodsItemClickHandler() {
        this.$emit('click')
      },
      // 单选按钮点击事件处理函数
      radioClickHandler() {
        this.$emit('checkchange', {
          goods_id: this.goods.goods_id,
          is_checked: this.goods.is_checked
        })
      },
      // 数字选择框值变化的事件处理函数
      noboxChange(val) {
        this.$emit('countchange', {
          goods_id: this.goods.goods_id,
          value: val
        })
      }
    }
  }
</script>

<style lang="scss">
  .goods-item {
    display: flex;
    padding: 10px 5px;
    border-bottom: 1px solid #efefef;
    width: 100%;

    .left {
      .thumb {
        width: 180rpx;
        height: 180rpx;
        display: block;
      }

      margin-right: 5px;
    }

    .right {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding: 4px;
      flex: 1;

      .title {
        font-size: 12px;
      }

      .price {
        font-size: 16px;
        color: #C00000;
      }
    }
  }

  .thumb-box {
    display: flex;
    align-items: center;

    .thumb {
      width: 180rpx;
      height: 180rpx;
      margin-left: 5rpx;
    }
  }

  .desc-box {
    display: flex;
    align-items: center;
    justify-content: space-between;

    .price {
      font-size: 16px;
      color: #C00000;
    }
  }
</style>
